<?php
/**
 * Elgg messageboard widget view
 *
 */

$owner = elgg_get_page_owner_entity();
$guid = elgg_get_logged_in_user_guid();

$num_display = $vars['entity']->num_display;
//print_r($owner);
//print_r($guid);
?>
<ul id="messageboard" class="elgg-menu elgg-menu-filter elgg-menu-hz elgg-menu-filter-default">
	<li id="li_1" class="elgg-state-selected"><a id="a_1" href="#">Market view</a></li>
	<li id="li_2" class=""><a id="a_2" href="#">Work plan</a></li>
<div id="viewall_1" style="text-align:right;display:block;">
<?php
if ($owner instanceof ElggGroup) {
	$url = "messageboard/group/$owner->guid/all";
} else {
	$url = "messageboard/owner/$owner->username";
}
echo elgg_view('output/url', array(
	'href' => $url."?message_type=1",
	'text' => elgg_echo('messageboard:viewall'),
	'is_trusted' => true,
	'style' => 'display:inline;white-space:nowrap',
));
?>
</div>
<div id="viewall_2" style="text-align:right;display:none;">
<?php
if ($owner instanceof ElggGroup) {
	$url = "messageboard/group/$owner->guid/all";
} else {
	$url = "messageboard/owner/$owner->username";
}
echo elgg_view('output/url', array(
	'href' => $url."?message_type=2",
	'text' => elgg_echo('messageboard:viewall'),
	'is_trusted' => true,
	'style' => 'display:inline;white-space:nowrap',
));
?>
</div>
</ul>
<script>
$(document).ready(function(){
	//$("div#messageboard_1").show();
	//$("div#messageboard_2").hide();
	$("ul#messageboard li a#a_1").click(function(){
		//console.log($(this).attr("id"));
		$("div#messageboard_1").show();
		$("div#messageboard_2").hide();
		$("div#viewall_1").show();
		$("div#viewall_2").hide();
		//console.log($("ul#messageboard li#1").attr("class"));
		$("ul#messageboard li#li_1").addClass("elgg-state-selected");
		$("ul#messageboard li#li_2").removeClass("elgg-state-selected");
	});
	$("ul#messageboard li a#a_2").click(function(){
		//console.log($(this).attr("id"));
		$("div#messageboard_2").show();
		$("div#messageboard_1").hide();
		$("div#viewall_2").show();
		$("div#viewall_1").hide();
		//console.log($("ul#messageboard li#1").attr("class"));
		$("ul#messageboard li#li_2").addClass("elgg-state-selected");
		$("ul#messageboard li#li_1").removeClass("elgg-state-selected");
	});
});
</script>
<div id="messageboard_1" style="display:block;">
<?php
$options = array(
	'annotations_name' => 'messageboard_1',
	'guid' => $owner->getGUID(),
	'limit' => $num_display,
	'pagination' => false,
	'reverse_order_by' => true,
);

echo elgg_list_annotations($options);

if (elgg_is_logged_in() && ($owner->guid==$guid)) {
	echo elgg_view_form('messageboard/add', array('name' => 'elgg-messageboard'), array('message_type' => '1'));
}

?>
</div>
<div id="messageboard_2" style="display:none;">
<?php
$options = array(
	'annotations_name' => 'messageboard_2',
	'guid' => $owner->getGUID(),
	'limit' => $num_display,
	'pagination' => false,
	'reverse_order_by' => true,
);

echo elgg_list_annotations($options);

if ($owner instanceof ElggGroup) {
	$url = "messageboard/group/$owner->guid/all";
} else {
	$url = "messageboard/owner/$owner->username";
}

if (elgg_is_logged_in() && ($owner->guid==$guid)) {
	echo elgg_view_form('messageboard/add', array('name' => 'elgg-messageboard'), array('message_type' => '2'));
}

?>
</div>
